/*
 * IdeogramData.java
 * Prakash Manandhar, pmanandhar@umassd.edu
 * Created Dec 24, 2010
 */

package ideogrammaker;

import javax.swing.table.DefaultTableModel;

/**
 * 
 * @author Prakash Manandhar pmanandhar@umassd.edu
 */
public final class IdeogramData extends DefaultTableModel {
    public IdeogramData() {
        this.addColumn("Long-Arm");
        this.addColumn("LA-Sat");
        this.addColumn("Short-Arm");
        this.addColumn("SA-Sat");
        addRow();
    }

    public void addRow() {
        Float [] rowData = {1.0f, 0.1f, 0.5f, 0.0f};
        this.addRow(rowData);
    }

    public float getMax() {
        float max = 0.0f;
        for(int i = 0; i < this.getRowCount(); i++)
        {
            float la = this.getFloatAt(i, 0) + this.getFloatAt(i, 1);
            float sa = this.getFloatAt(i, 2) + this.getFloatAt(i, 3);
            if (la > max) max = la;
            if (sa > max) max = sa;
        }
        return max;
    }

    public float getFloatAt(int i, int j) {
        Object o = this.getValueAt(i, j);
        float v;
        try {
            v = Float.valueOf(o.toString());
        } catch (NumberFormatException e) {
            v = 0.0f;
        }
        return v;
    }
}
